<?

/***************************************************************************
 Jupiter Content System @ Jupiterportal.com
 Copyright (C) 2005 Cosmin Flavius (highstrike@gmail.com)

 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 as published by the Free Software Foundation; either version 2
 of the License, or (at your option) any later version.

 More Info About The Licence At http://www.gnu.org/copyleft/gpl.html
****************************************************************************/

function b_today()
{
	$name_function = "b_today";

	global $a, $db, $blocks_db, $template, $language, $config, $misc, $PHP_SELF,
           $is_loged_in, $is_moderator, $is_administrator, $is_webmaster, $months,
           $days, $m, $y, $OnlineGuestsCount, $OnlineMembersCount, $sitelanguage;
	if(!file_exists("blocks/$name_function/language/$sitelanguage.php"))
        include "blocks/$name_function/language/en.php";
	else include "blocks/$name_function/language/$sitelanguage.php";

	$random_code = md5("$name_function");
	$random_code = substr("$random_code", 0, 5);

	if(!isset($content)) $content = NULL;
	if(!isset($_GET["$random_code"])) $_GET["$random_code"] = NULL;

	if($_GET["$random_code"] == "on") $_SESSION["$random_code"] = "on";
	elseif($_GET["$random_code"] == "off") $_SESSION["$random_code"] = "off";

	$query_string = "?{$_SERVER['QUERY_STRING']}";

	foreach($blocks_db as $blocks)
	{
		$block_code = md5("{$blocks['name']}");
		$block_code = substr("$block_code", 0, 5);

		$query_string = str_replace("&$block_code=off","", $query_string);
		$query_string = str_replace("&$block_code=on","", $query_string);
	}

	if($query_string == "?" || strpos($query_string, '=on') !== false || strpos($query_string, '=off') !== false) $code_query = "?";
	else $code_query = "$query_string&";

	if(!isset($_SESSION["$random_code"]) || $_SESSION["$random_code"] == "on") $links = "<a href='$code_query$random_code=off'><img src='templates/$template/images/misc/minus.gif' border='0'> {$language_block['Events title']}</a>";
	elseif($_SESSION["$random_code"] == "off") $links = "<a href='$code_query$random_code=on'><img src='templates/$template/images/misc/plus.gif' border='0'> {$language_block['Events title']}</a>";

	$template_block = implode("", file("templates/$template/block_today.php"));
	$template_block = str_replace("{template}", $template, $template_block);
	$template_block = str_replace("{links}", $links, $template_block);

	if(!isset($_SESSION["$random_code"]) || $_SESSION["$random_code"] == "on")
	{
		//-----------------------------------------------------------------
		//  Get users and today's events
		//-----------------------------------------------------------------

		$today_events = $db->getTable("SELECT type, user_id, user_user, start, end, title, age FROM events LEFT JOIN users ON events.user_id = users.id WHERE day = '".date('j')."' AND month = '".date('n')."' AND year = '".date('Y')."' ORDER BY start ASC,type DESC");

		//-----------------------------------------------------------------
		//  Do foreach
		//-----------------------------------------------------------------

		if($today_events != FALSE)
		{
			foreach($today_events as $idx=>$today_event)
			{
				if($today_event['start'] != 0 || $today_event['end'] != 0) $start_end = "".date("H:i",$today_event['start'])." - ".date("H:i",$today_event['end'])."";
				else $start_end = "{$language_block['Events allday']}";

				if($today_event['type'] == "bday") $content .= "<tr class='".row2color($idx)."' onMouseOver=this.className='con3' onMouseOut=this.className='".row2color($idx)."' onclick=window.location.href='$PHP_SELF?n=modules/events&d=".date("j")."&m=".date("n")."'><td class='con1-today'>{$language_block['Events bday1']} <a href='$PHP_SELF?n=modules/users&a=1&d={$today_event['user_id']}'>{$today_event['user_user']}</a> {$language_block['Events bday2']} ".find_age("{$today_event['age']}")." {$language_block['Events bday3']}</td></tr>";
				else 
				{
					if(isset($today_event['age'])) $content .= "<tr class='".row2color($idx)."' onMouseOver=this.className='con3' onMouseOut=this.className='".row2color($idx)."' onclick=window.location.href='$PHP_SELF?n=modules/events&d=".date("j")."&m=".date("n")."'><td class='con1-today'>[ $start_end ]<br><a href='$PHP_SELF?n=modules/users&a=1&d={$today_event['user_id']}'>{$today_event['user_user']}</a>: ".parse_message($today_event['message'])."</td></tr>";
					else $content .= "<tr class='".row2color($idx)."' onMouseOver=this.className='con3' onMouseOut=this.className='".row2color($idx)."' onclick=window.location.href='$PHP_SELF?n=modules/events&d=".date("j")."&m=".date("n")."'><td class='con1-today'>[ $start_end ]<br>".parse_message($today_event['title'])."</td></tr>";
				}
			}
		}
		else $content .= "<tr><td class='con1-today'>{$language_block['Events none']}</td></tr>";
	}

	$template_block = str_replace("{content}", $content, $template_block);
	$output = $template_block;

return $output;
}

?>
